package restaurant.iterators;

import static org.junit.Assert.*;

import java.util.NoSuchElementException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import restaurant.Menu;
import restaurant.MenuItem;

/**
 * Test case for the ByPrepTimeIterator class. Tests to ensure the
 * {@code hasNext} and {@code next} methods work correctly.
 * 
 * @author Odessa
 */
public class ByPrepTimeIteratorTest
{
	Menu menu;
	Iterator it;



	/**
	 * Sets up the test fixture.
	 * 
	 * @throws Exception the exception
	 */
	@Before
	public void setUp() throws Exception
	{
		menu = new Menu();
		menu.createItem(
				"Sizzling Apple Pie",
				"Layer upon layer of apple atop a light, flaky crust topped "
						+ "with walnut streusel, rich caramel butter sauce and "
						+ "a scoop of vanilla ice cream. ", 5.99, 10,
				"Dessert", false);
	}



	/**
	 * Tears down the test fixture.
	 * 
	 * @throws Exception the exception
	 */
	@After
	public void tearDown() throws Exception
	{
		menu = null;
		it = null;
	}



	/**
	 * Test method for {@link restaurant.iterators.ByPrepTimeIterator#hasNext()}. Tests
	 * hasNext() if there are more items on the menu with a lower preparation
	 * time than the one specified.
	 */
	@Test
	public void testHasNext_Yes()
	{
		it = menu.getByPrepTimeIterator(15);
		assertTrue(it.hasNext());
	}



	/**
	 * Test method for {@link restaurant.iterators.ByPrepTimeIterator#hasNext()}. Tests
	 * hasNext() if there are no more items on the menu with a lower preparation
	 * time than the one specified.
	 */
	@Test
	public void testHasNext_No()
	{
		it = menu.getByPrepTimeIterator(5);
		assertFalse(it.hasNext());
	}



	/**
	 * Test method for {@link restaurant.iterators.ByPrepTimeIterator#next()}. Tests
	 * next() if there are more items on the menu with a lower preparation time
	 * than the one specified.
	 */
	@Test(expected = NoSuchElementException.class)
	public void testNext_MoreItems()
	{
		it = menu.getByPrepTimeIterator(15);
		MenuItem m = new MenuItem(
				1,
				"Sizzling Apple Pie",
				"Layer upon layer of apple atop a light, flaky crust topped "
						+ "with walnut streusel, rich caramel butter sauce and "
						+ "a scoop of vanilla ice cream. ", 5.99, 10,
				"Dessert", false);

		assertEquals(m, it.next());
	}



	/**
	 * Test method for {@link restaurant.iterators.ByPrepTimeIterator#next()}. Tests
	 * next() if there are no more items on the menu with a lower preparation
	 * time than the one specified.
	 */
	@Test(expected = NoSuchElementException.class)
	public void testNext_NoMoreItems()
	{
		it = menu.getByPrepTimeIterator(5);
		it.next();
	}

}
